#pragma once

#include <windows.h>
#include "resource.h"

//Handles
HINSTANCE HandleInstance;
HWND HandleWindow;

HWND hScene;
#define ID_SCENE			101
HWND hStaticInfo;
#define ID_INFO				102

#define ID_BUTTON_DECLARE	201
#define ID_PARAM_SIZE		202
#define ID_PARAM_AGENTS		203

#define ID_PARAM_RATIO		204
#define ID_PARAM_SMOOTH		205
#define ID_BUTTON_TERRAIN	206

//#define ID_BUTTON_IDLE		207
#define ID_BUTTON_RUN		208
#define ID_PARAM_SPEED		209
#define ID_PARAM_FRAMERATE	210
#define ID_BUTTON_COMPUTE	211

#define ID_PARAM_THINKCYCLE	212
#define ID_BUTTON_MODULATE	213


#define ID_BUTTON_SEED		214

template <typename T>
T LimitNum(T Min, T Max, T Val)
{
	if (Val > Max) Val = Max;
	if (Val < Min) Val = Min;
	return Val;
}

template <typename T>
T MultipleNum(T Val, T Base)
{
	Val = Val / Base;
	Val = Val * Base;
	return Val;
}

namespace Gui
{
	#define PARAM_BUFFER 32

	HWND HandleGui[128];
	int HandleCount = 0;

	int RowGui = 0;

	void AddRadioButtonGroup(LPCWSTR ClassName, int ID, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindowEx(WS_EX_WINDOWEDGE,
			L"BUTTON",
			ClassName,
			WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_GROUP,
			5, 5 + 25 * RowGui,
			190, 18,
			hWnd, 
			(HMENU)ID, //das ist falsch oder???
			HandleInstance, NULL);
		++RowGui;
	}
	void AddRadioButton(LPCWSTR ClassName, int ID, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindowEx(WS_EX_WINDOWEDGE,
			L"BUTTON",
			ClassName,
			WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
			5, 5 + 25 * RowGui,
			190, 18,
			hWnd,
			(HMENU)ID, //das ist falsch oder???
			HandleInstance, NULL);
		++RowGui;
	}
	void AddButton(LPCWSTR ClassName, int ID, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindow(L"BUTTON", ClassName,
			WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
			5, 5 + 25 * RowGui,
			190, 18,
			hWnd, (HMENU)ID,
			HandleInstance, NULL);
		++RowGui;
	}
	void AddCheckbox(LPCWSTR ClassName, int ID, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindowEx(WS_EX_WINDOWEDGE,
			L"BUTTON",
			ClassName,
			WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
			5, 5 + 25 * RowGui,
			190, 18,
			hWnd,
			(HMENU)ID, //das ist falsch oder???
			HandleInstance, NULL);
		++RowGui;
	}


	void AddParameter(LPCWSTR ClassName, LPCWSTR ClassDefault, int ID, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindow(L"STATIC", ClassName,
			WS_CHILD | WS_VISIBLE,
			5, 5 + 25 * RowGui,
			135, 18,
			hWnd, (HMENU)0,
			HandleInstance, NULL);

		HandleGui[RowGui] = CreateWindow(L"EDIT", ClassDefault,
			WS_CHILD | WS_VISIBLE | EN_CHANGE,
			145, 5 + 25 * RowGui,
			50, 18,
			hWnd, (HMENU)ID,
			HandleInstance, NULL);
		++RowGui;
	}

	void AddLabel(LPCWSTR ClassName, HWND hWnd)
	{
		HandleGui[RowGui] = CreateWindow(L"STATIC", ClassName,
			WS_CHILD | WS_VISIBLE,
			5, 5 + 25 * RowGui,
			190, 18,
			hWnd, (HMENU)0,
			HandleInstance, NULL);
		++RowGui;
	}

	int GetInt(int ID, HWND hWnd)
	{
		TCHAR Buffer[PARAM_BUFFER];
		GetWindowText(GetDlgItem(hWnd, ID), Buffer, PARAM_BUFFER);
		return _ttoi(Buffer);
	}
	void SetInt(int Value, int ID, HWND hWnd)
	{
		TCHAR Buffer[PARAM_BUFFER];
		_stprintf_s(Buffer, L"%i", Value);
		SetWindowText(GetDlgItem(hWnd, ID), Buffer);
	}


	void AddSpace()
	{
		++RowGui;
	}
};